package ${package.Controller};

<#if genPage>
import com.ozo.easy.common.model.*;
</#if>
<#if genOperateLog>
import com.ozo.easy.common.log.annotation.LogAnno;
</#if>
<#if genAdd || genEdit>
import ${package.SaveDTO}.${entity}SaveDTO;
</#if>
<#if genPage>
import ${package.QueryDTO}.${entity}QueryDTO;
import ${package.VO}.${entity}VO;
</#if>
import ${package.Service}.I${entity}Service;
<#if genPage>
import io.swagger.v3.oas.annotations.Operation;
</#if>
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
<#if genEdit>
import org.springframework.validation.annotation.Validated;
</#if>
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
<#if genPage>
import javax.validation.Valid;
</#if>
<#if genPage && genPageTableType == 'LIST'>
import java.util.List;
</#if>

/**
 * ${function} 前端控制器
 *
 * @author ${author}
 * @version ${version}
 * @date ${date}
 */
@Tag(name = "${function}")
@RequiredArgsConstructor
@RestController
@RequestMapping("/${entityName}")
public class ${entity}Controller {

    private final I${entity}Service ${entityName}Service;

<#if genPage>
    @Operation(summary = "表格页")
    @GetMapping("/index")
    public ModelAndView index() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("${entityName}/index");
        return modelAndView;
    }

</#if>
<#if genAdd>
    @Operation(summary = "添加页")
    @GetMapping("/addForm")
    public ModelAndView addForm() {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("${entityName}/addForm");
        return modelAndView;
    }

</#if>
<#if genEdit>
    @Operation(summary = "编辑页")
    @GetMapping("/editForm/{id}")
    public ModelAndView editForm(@PathVariable Long id) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("data", ${entityName}Service.detail(id));
        modelAndView.setViewName("${entityName}/editForm");
        return modelAndView;
    }

</#if>
<#if genAdd>
    <#if genOperateLog>
    @LogAnno(value = "添加${function}", module = "${function}")
    </#if>
    @Operation(summary = "添加${function}")
    @PostMapping("/add")
    public ResultVO<Void> add(@RequestBody @Valid ${entity}SaveDTO saveDTO) {
        ${entityName}Service.add(saveDTO);
        return ResultVO.success();
    }

</#if>
<#if genRemove>
    <#if genOperateLog>
    @LogAnno(value = "删除${function}", module = "${function}")
    </#if>
    @Operation(summary = "删除${function}")
    @DeleteMapping("/remove")
    public ResultVO<Void> remove(@RequestBody @Valid BaseBatchDTO<Long> batchDTO) {
        ${entityName}Service.remove(batchDTO);
        return ResultVO.success();
    }

</#if>
<#if genEdit>
    <#if genOperateLog>
    @LogAnno(value = "编辑${function}", module = "${function}")
    </#if>
    @Operation(summary = "编辑${function}")
    @PutMapping("/edit")
    public ResultVO<Void> edit(@RequestBody @Validated(value = BaseValidDTO.Edit.class) ${entity}SaveDTO saveDTO) {
        ${entityName}Service.edit(saveDTO);
        return ResultVO.success();
    }

</#if>
<#if genPage>
<#if genPageTableType == 'PAGE'>
    @Operation(summary = "${function}分页")
    @GetMapping("/page")
    public ResultVO<PageResult<${entity}VO>> page(@Valid BasePage basePage, ${entity}QueryDTO queryDTO) {
        return ResultVO.success(${entityName}Service.page(basePage, queryDTO));
    }

<#else>
    @Operation(summary = "${function}列表")
    @GetMapping("/list")
    public ResultVO<List<${entity}VO>> list(${entity}QueryDTO queryDTO) {
        return ResultVO.success(${entityName}Service.list(queryDTO));
    }

</#if>
</#if>
}